package negModel;

import negModelExcep.eParteNoFunciona;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Neumatico extends PartePerformance {

	private double perimetro;
	private double ancho;
	private double coeficiente;
	
	public Neumatico(){}
	
	public Neumatico (int vidaUtil, double peso,float aporteVelMax,String detalle,AlgoPesos precio,boolean removible,int performance, double perimetro,double ancho, double coef){
		this.setMaxVU(vidaUtil);
		this.arreglar();
		this.setPeso(peso);
		this.setAportevmax(aporteVelMax);
		this.setDetalle(detalle);
		this.setPrecio(precio);
		this.setRemovible(removible);
		this.setPerformance(performance);
			
		this.perimetro = perimetro;
		this.ancho = ancho;
		this.coeficiente = coef;
	}
	
	public Neumatico (Element xmlElement) {
		this.setMaxVU(Integer.parseInt(xmlElement.getAttribute("maxVU")));
		this.setVidaUtil(Integer.parseInt(xmlElement.getAttribute("vidaUtil")));
		this.setPeso(Double.parseDouble(xmlElement.getAttribute("peso")));
		this.setAportevmax(Float.parseFloat(xmlElement.getAttribute("aportevmax")));
		this.setDetalle(xmlElement.getAttribute("detalle"));
		this.setPrecio(new AlgoPesos(Double.parseDouble(xmlElement.getAttribute("precio"))));
		this.setRemovible(Boolean.parseBoolean(xmlElement.getAttribute("removible")));
		this.setPerformance(Integer.parseInt(xmlElement.getAttribute("performance")));
		
		this.perimetro=Double.parseDouble(xmlElement.getAttribute("perimetro"));
		this.ancho=Double.parseDouble(xmlElement.getAttribute("ancho"));
		this.coeficiente=Double.parseDouble(xmlElement.getAttribute("coeficiente"));
	}
	
	public Element toXml(Document doc) {
		Element xmlElement = doc.createElement("parteInterna");
		xmlElement.setAttribute("Clase","neumatico");
		
		xmlElement.setAttribute("maxVU", ""+ this.getMaxVU());
		xmlElement.setAttribute("vidaUtil", ""+this.getVidaUtil());
		xmlElement.setAttribute("peso", ""+this.getPeso());
		xmlElement.setAttribute("aportevmax", ""+ this.aportevmax());
		xmlElement.setAttribute("detalle", this.getDetalle());
		xmlElement.setAttribute("precio", ""+(this.getPrecio()).getMonto());
		xmlElement.setAttribute("removible", ""+this.esRemovible());
		xmlElement.setAttribute("performance", ""+this.getPerformance());
		
		xmlElement.setAttribute("perimetro", ""+this.perimetro);
		xmlElement.setAttribute("ancho", ""+this.ancho);
		xmlElement.setAttribute("coeficiente", ""+this.coeficiente);
				
		return xmlElement;
	}
	
	public double funcionar() throws eParteNoFunciona {
		this.gastar();
		return (ancho / perimetro) * coeficiente;
	}

	public double getPerimetro() {
		return perimetro;
	}
	
	public double getAncho(){
		return ancho;
	}

	public double getCoeficiente() {
		return coeficiente;
	}

	

	
}
